box-shadow: For top/bottom and left/right parts, repeat a single line
authorAlexander Larsson <alexl@redhat.com>
Fri, 20 Mar 2015 13:56:42 +0000 (14:56 +0100)
committerAlexander Larsson <alexl@redhat.com>
Sat, 21 Mar 2015 20:39:15 +0000 (21:39 +0100)
Since these part really are the same in all of the x or y direction
and we don't blur in that direction we can just blur one line and
repeat it during drawing.

https://bugzilla.gnome.org/show_bug.cgi?id=746468

gtk/gtkcairoblurprivate.h
gtk/gtkcssshadowvalue.c

index 970c0826d80066f98a94b9df607047a5618a83d1..68126d3b5b78fc4d44b281d17991152311a8840c 100644 (file)
@@ -32,7 +32,8 @@ G_BEGIN_DECLS
 typedef enum {
   GTK_BLUR_NONE = 0,
   GTK_BLUR_X = 1<<0,
-  GTK_BLUR_Y = 1<<1
+  GTK_BLUR_Y = 1<<1,
+  GTK_BLUR_REPEAT = 1<<2
 } GtkBlurFlags;
 
 void            _gtk_cairo_blur_surface         (cairo_surface_t *surface,
index 341844f75133c1b478d514869ef0fef1d6ab0cf1..ffdc2b6250dbe3013eccabb736d9f21ed0760ca1 100644 (file)
@@ -328,6 +328,14 @@ gtk_css_shadow_value_start_drawing (const GtkCssValue *shadow,
   radius = _gtk_css_number_value_get (shadow->radius, 0);
   clip_radius = _gtk_cairo_blur_compute_pixels (radius);
 
+  if (blur_flags & GTK_BLUR_REPEAT)
+    {
+      if (!blur_x)
+        clip_rect.width = 1;
+      if (!blur_y)
+        clip_rect.height = 1;
+    }
+
   /* Create a larger surface to center the blur. */
   surface = cairo_surface_create_similar_image (cairo_get_target (cr),
                                                 CAIRO_FORMAT_A8,
@@ -350,6 +358,20 @@ gtk_css_shadow_value_start_drawing (const GtkCssValue *shadow,
   return blur_cr;
 }
 
+void
+mask_surface_repeat (cairo_t         *cr,
+                     cairo_surface_t *surface)
+{
+    cairo_pattern_t *pattern;
+
+    pattern = cairo_pattern_create_for_surface (surface);
+    cairo_pattern_set_extend (pattern, CAIRO_EXTEND_REPEAT);
+
+    cairo_mask (cr, pattern);
+
+    cairo_pattern_destroy (pattern);
+}
+
 static cairo_t *
 gtk_css_shadow_value_finish_drawing (const GtkCssValue *shadow,
                                      cairo_t           *cr,
@@ -370,7 +392,10 @@ gtk_css_shadow_value_finish_drawing (const GtkCssValue *shadow,
   _gtk_cairo_blur_surface (surface, radius, blur_flags);
 
   gdk_cairo_set_source_rgba (original_cr, _gtk_css_rgba_value_get_rgba (shadow->color));
-  cairo_mask_surface (original_cr, surface, 0, 0);
+  if (blur_flags & GTK_BLUR_REPEAT)
+    mask_surface_repeat (original_cr, surface);
+  else
+    cairo_mask_surface (original_cr, surface, 0, 0);
 
   cairo_destroy (cr);
 
@@ -740,7 +765,7 @@ _gtk_css_shadow_value_paint_box (const GtkCssValue   *shadow,
       /* Then the sides */
       for (i = 0; i < 4; i++)
        {
-          GtkBlurFlags blur_flags = 0;
+          GtkBlurFlags blur_flags = GTK_BLUR_REPEAT;
 
          if (i == GTK_CSS_TOP || i == GTK_CSS_BOTTOM)
            {